package controllers

import (
	"github.com/goravel/framework/contracts/http"
	"github.com/goravel/framework/facades"
	"goravel/app/models"
)

type HttpController struct {
	//Dependent services
}

func NewHttpController() *HttpController {
	return &HttpController{
		//Inject services
	}
}

type Req struct {
	Label string `json:"label"`
	Value string `json:"value"`
}

func (r *HttpController) ReadOpt(ctx http.Context) http.Response {
	parameter := ctx.Request().Query("parameter", "")
	var reqs []Req

	if parameter == "" {
		facades.Orm().Query().Model(&models.Readcmd{}).Select("parameter as label,id as value").Scan(&reqs)
	} else {
		facades.Orm().Query().Model(&models.Readcmd{}).Where("parameter like ?", "%"+parameter+"%").Select("parameter as label,id as value").Scan(&reqs)
	}
	return ctx.Response().Success().Json(reqs)
}
